#ifndef JSERVICE_H
#define JSERVICE_H
#include <string>
#include <vector>
#include <list>
struct JServiceMsg;
class JServiceRunner;
class JService {
public:
	virtual ~JService();
	JService();
	virtual void onStart(void* startArgs);
	virtual void onMsg(JService* service, int msgId, int sessionId, void* args);
	void sendMsg(int sourceId, int msgId, int sessionId, void* args);
	int getId();
public:
	friend class JServiceRunner;
private:
	bool tryQueueMsg(JServiceMsg* msg);
	JServiceMsg* dequeueMsg();
	void markWorking();
	void unmarkWorking();
private:
	std::list<JServiceMsg*> m_listMsgs;
	bool m_working;
	int m_id;
	JServiceRunner* m_runner;
	int refCount;
	int m_startTime;
};
#endif
